package icu.qx.gbs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import icu.qx.gbs.mapper.GbsGoodUrlMapper;
import icu.qx.gbs.domain.GbsGoodUrl;
import icu.qx.gbs.service.IGbsGoodUrlService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 物品图片Service业务层处理
 *
 * @author yong
 * @date 2024-06-30
 */
@Service
public class GbsGoodUrlServiceImpl implements IGbsGoodUrlService {
    @Autowired
    private GbsGoodUrlMapper gbsGoodUrlMapper;

    /**
     * 查询物品图片
     *
     * @param urlId 物品图片主键
     * @return 物品图片
     */
    @Override
    public GbsGoodUrl selectGbsGoodUrlByUrlId(Long urlId) {
        return gbsGoodUrlMapper.selectGbsGoodUrlByUrlId(urlId);
    }

    /**
     * 查询物品图片列表
     *
     * @param gbsGoodUrl 物品图片
     * @return 物品图片
     */
    @Override
    public List<GbsGoodUrl> selectGbsGoodUrlList(GbsGoodUrl gbsGoodUrl) {
        return gbsGoodUrlMapper.selectGbsGoodUrlList(gbsGoodUrl);
    }

    /**
     * 新增物品图片
     *
     * @param gbsGoodUrl 物品图片
     * @return 结果
     */
    @Override
    public int insertGbsGoodUrl(GbsGoodUrl gbsGoodUrl) {
        gbsGoodUrl.setCreateTime(DateUtils.getNowDate());
        return gbsGoodUrlMapper.insertGbsGoodUrl(gbsGoodUrl);
    }

    @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
    @Override
    public int insertGbsGoodUrls(List<GbsGoodUrl> gbsGoodUrls) {
        GbsGoodUrl url = gbsGoodUrls.get(0);
        gbsGoodUrlMapper.deleteGbsGoodUrlByPdCode(url.getUrlPdCode());
        gbsGoodUrls.forEach(gbsGoodUrl -> {
            gbsGoodUrl.setCreateTime(DateUtils.getNowDate());
            gbsGoodUrl.setCreateBy(SecurityUtils.getUsername());
            gbsGoodUrlMapper.insertGbsGoodUrl(gbsGoodUrl);
        });
        return 1;
    }

    /**
     * 修改物品图片
     *
     * @param gbsGoodUrl 物品图片
     * @return 结果
     */
    @Override
    public int updateGbsGoodUrl(GbsGoodUrl gbsGoodUrl) {
        gbsGoodUrl.setUpdateTime(DateUtils.getNowDate());
        return gbsGoodUrlMapper.updateGbsGoodUrl(gbsGoodUrl);
    }

    /**
     * 批量删除物品图片
     *
     * @param urlIds 需要删除的物品图片主键
     * @return 结果
     */
    @Override
    public int deleteGbsGoodUrlByUrlIds(Long[] urlIds) {
        return gbsGoodUrlMapper.deleteGbsGoodUrlByUrlIds(urlIds);
    }

    /**
     * 删除物品图片信息
     *
     * @param urlId 物品图片主键
     * @return 结果
     */
    @Override
    public int deleteGbsGoodUrlByUrlId(Long urlId) {
        return gbsGoodUrlMapper.deleteGbsGoodUrlByUrlId(urlId);
    }
}
